var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var PageBase = require('../../common/PageBase.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
var app = getApp();

Page(common.extendPage(PageBase, {
	data: {
		dataLoaded: false,
		logoImg: ''
	},

	onLoad(options) {
		this._options = this.options;

		common.initApp({
			extSuc: () => {
				this._fetch();
			},
			loginSuc: () => {
				this.setData({
					logoImg: app.getLogoImg()
				});
				this.$loginSuc();
			},
			sysInfoSuc: (sysInfo) => {
				this.setData({
					winHei: app.getWinHei(),
				});
			},
		});
	},

	onShareAppMessage: function(res) {
		return {
			title: this.data.actInfo.title,
			path: '/pages/actDetail/index?id=' + this._options.id,
			success: function(res) {
				// 转发成功
			},
			fail: function(res) {
				// 转发失败
			}
		}
	},

	_fetch() {
		ajax.G({
			url: '/market/Home/actInfo',
			data: {
				act_id: this._options.id
			},
			success: (res) => {
				var {
					actInfo = []
				} = res.result;

				WxParse.wxParse('article', 'html', actInfo.content, this, 0);

				this.setData({
					dataLoaded: true,
					actInfo
				});
			}
		});
	}

}));